﻿var iReport = new Object();

iReport.codebase = "/resource/cab/iReport.cab#version=1,1,0,28"
iReport.PreViewHtmlName = "/resource/html/report/PreView.html";
iReport.InstallHtmlName = "";

////////////////////////////////////////////////


iReport.version = 1.8;

iReport.PREVIEW = 0;
iReport.PRINT = 1;
iReport.DIRECTPRINT = 2;
iReport.PRINTEXCELPREVIEW = 3;
iReport.PRINTEXCELFILE = 4;
iReport.PRINTEXCELFILENAME = 5;

iReport.CIPHER_NONE = 0;
iReport.CIPHER_XECURE = 1;

iReport.ViewType = iReport.PREVIEW;
iReport.Width = 800;
iReport.Height = 600;

iReport.CipherType = iReport.CIPHER_NONE;

iReport.params = new Array();
iReport.URL = "";
iReport.ResForm = "";
iReport.ReportOcx = null;
iReport.XmlString = "";


iReport.iParams = function()
{
}

iReport.iParams.name = "";
iReport.iParams.value = "";

iReport.Install = function(codebase)
{
	if(codebase != undefined)
		iReport.codebase = codebase;

	iReport.Installc(iReport.codebase);
}

iReport.Installc = function(codebase)
{
	if(codebase != undefined)
		iReport.codebase = codebase;

	document.write("<OBJECT  name='iReportObject' id='iReport' style='WIDTH: 0%; HEIGHT: 0%' codebase="+codebase+" classid='CLSID:EF0D7593-0CB1-4236-9D56-C62B47FEAABB'></OBJECT>");
}

iReport.ViewInstall = function()
{
	if( arguments[0] != null )
	{
		iReport.ReportOcx = arguments[0];
	}
	else
	{
		document.write("<OBJECT  name='iReportOcx' id='print' style='WIDTH:100%; HEIGHT:100%' classid='CLSID:6D0E4F00-0C1D-4BD4-BF23-8A665FDFDAEA' onError='notinstalled()'></OBJECT>");
		iReport.ReportOcx = document.all.iReportOcx;
	}
}

iReport.HiddenInstall = function()
{
	if( arguments[0] != null )
	{
		iReport.ReportOcx = arguments[0];
	}
	else
	{
		document.write("<OBJECT  name='iReportOcx' id='print' style='WIDTH:0%; HEIGHT:0%' codebase="+iReport.codebase+" classid='CLSID:6D0E4F00-0C1D-4BD4-BF23-8A665FDFDAEA'></OBJECT>");
		iReport.ReportOcx = document.all.iReportOcx;
	}
}


iReport.IsInstall = function()
{
	if( iReport.ReportOcx == null ) return false;
	if( iReport.ReportOcx.object==null) return false;

	return true;
}

iReport.Init = function()
{
	iReport.XmlString = "";
	iReport.ClearParam();
}

iReport.SetViewType = function(nType)
{
	iReport.ViewType = nType;
}

iReport.GetViewType = function()
{
	return iReport.ViewType;
}

iReport.SetURL = function(value)
{
	iReport.URL = value;
}

iReport.SetCiphierType = function(value)
{
	iReport.CipherType = value;
}

iReport.GetCiphierType = function()
{
	return iReport.CipherType;
}

iReport.SetResForm = function(value)
{
	iReport.ResForm = value;
}

iReport.GetURL = function(value)
{
	return iReport.URL;
}

iReport.GetResForm = function(value)
{
	return iReport.ResForm;
}

iReport.SetSize = function(_width, _height)
{
	iReport.Width = _width;
	iReport.Height = _height;
}

iReport.SetArgument = function(arguments)
{
	iReport.URL = arguments.URL;
	iReport.ResForm = arguments.ResForm;
	iReport.CipherType = arguments.CipherType;
	iReport.params = arguments.params;
}

iReport.AddParam = function(name, value)
{
	var paramlen = iReport.GetParamCount();

	var _iParams = new iReport.iParams;
	_iParams.name = name;
	_iParams.value = value;

	iReport.params[paramlen] = _iParams;
}

iReport.ClearParam = function()
{
	var paramlen = iReport.GetParamCount();

	for(i=0;i<paramlen;i++)
	{
		iReport.params.pop();
	}
}

iReport.GetParamCount = function()
{
	return iReport.params.length;
}

iReport.GetName = function(nIndex)
{
	return iReport.params[nIndex].name;
}

iReport.GetValue = function(nIndex)
{
	return iReport.params[nIndex].value;
}

iReport.OpenOld = function(preview)
{
	var printmode = iReport.GetViewType();

	iReport.PreViewHtmlName = preview;

	if( printmode == iReport.PREVIEW )
	{
		var obj = new Object();
		obj.params = iReport.params;
		obj.URL = iReport.URL;
		obj.ResForm = iReport.ResForm;
		obj.CipherType = iReport.CipherType;

		var features = "dialogWidth:"+iReport.Width+"px;dialogHeight:"+iReport.Height+"px;resizable:yes;status:no;scroll:no;location:yes;";
		window.showModelessDialog(iReport.PreViewHtmlName, obj, features);
	}
	else
	{
		if( iReport.IsInstall() == false )
		{
			alert("i-Report 가 설치되지 않았습니다.");
			return;
		}

		if( printmode == iReport.PRINT )
		{
			iReport.Print();
		}
		else if( printmode == iReport.DIRECTPRINT )
		{
			iReport.DirerctPrint();
		}
		else if( printmode == iReport.PRINTEXCEL )
		{
			iReport.PrintExcel();
		}
	}
}

iReport.Open = function(preview)
{
	var printmode = iReport.GetViewType();

	iReport.PreViewHtmlName = preview;

	if(preview!=undefined)
		iReport.PreViewHtmlName = preview;

	if( printmode == iReport.PREVIEW )
	{
		var features = "left=150, top=0, width="+iReport.Width+", height="+iReport.Height+", toolbar=0, location=0, resizable=1, status=0"
		openwin = window.open(iReport.PreViewHtmlName, "iReportPreview", features);
		//openwin.window.setUrl(iReport.URL);
		//openwin.window.setResForm(iReport.ResForm);
		//openwin.window.setCipherType(iReport.CipherType);
		//openwin.window.setParams(iReport.params);
		//openwin.window.preview();
	}
	else
	{
		if( iReport.IsInstall() == false )
		{
			alert("i-Report 가 설치되지 않았습니다.");
			return;
		}

		if( printmode == iReport.PRINT )
		{
			iReport.Print();
		}
		else if( printmode == iReport.DIRECTPRINT )
		{
			iReport.DirerctPrint();
		}
		else if( printmode == iReport.PRINTEXCEL )
		{
			iReport.PrintExcel();
		}
	}
}

iReport.PreView = function()
{
	iReport.ReportOcx.SetParam("URL", iReport.GetURL());
	iReport.ReportOcx.SetParam("ResForm", iReport.GetResForm());

	iReport.SetCipher();
	iReport.SetParameters();

	if( iReport.XmlString != "" ) iReport.ReportOcx.SetXmlString(iReport.XmlString);

	iReport.ReportOcx.PreView();
}

iReport.Print = function()
{
	iReport.ReportOcx.SetParam("URL", iReport.GetURL());
	iReport.ReportOcx.SetParam("ResForm", iReport.GetResForm());

	iReport.SetCipher();
	iReport.SetParameters();

	if( iReport.XmlString != "" ) iReport.ReportOcx.SetXmlString(iReport.XmlString);

	iReport.ReportOcx.DoPrint();
}

iReport.DirerctPrint = function()
{
	iReport.ReportOcx.SetParam("URL", iReport.GetURL());
	iReport.ReportOcx.SetParam("ResForm", iReport.GetResForm());

	iReport.SetCipher();
	iReport.SetParameters();

	if( iReport.XmlString != "" ) iReport.ReportOcx.SetXmlString(iReport.XmlString);

	iReport.ReportOcx.DoPrintDirect();
}

iReport.PrintExcel = function()
{
	iReport.ReportOcx.SetParam("URL", iReport.GetURL());
	iReport.ReportOcx.SetParam("ResForm", iReport.GetResForm());

	iReport.SetCipher();
	iReport.SetParameters();

	if( iReport.XmlString != "" ) iReport.ReportOcx.SetXmlString(iReport.XmlString);

	if( arguments[0] != null )
	{
		if( arguments[0] == iReport.PRINTEXCELPREVIEW )
		iReport.ReportOcx.DoExcelPrint();
		else
			iReport.ReportOcx.DoExcelFileNamePrint(arguments[0]);
	}
	else
	{
			iReport.ReportOcx.DoExcelFilePrint();
	}
}

iReport.SetParameters = function()
{
	var paramlen = iReport.GetParamCount();
	for(i=0;i<paramlen;i++)
	{
		//alert(iReport.params[i].name + "     " + iReport.params[i].value );
		iReport.ReportOcx.AddRequestParam(iReport.params[i].name, iReport.params[i].value);
	}

}

iReport.SetCipher = function()
{
	if( iReport.GetCiphierType() == iReport.CIPHER_XECURE )
	{
		iReport.ReportOcx.SetXecure(1);
	}

}

iReport.SetXmlString = function(xmlstring)
{
	iReport.XmlString = xmlstring;
}

iReport.SetEndPrintEvent = function(value)
{
	iReport.ReportOcx.SetEndPrintEvent(value);
}

iReport.SetEventOnDataRecv = function(value)
{
	iReport.ReportOcx.SetEventOnDataRecv(value);
}

